package com.gs.process.core;

import com.alibaba.fastjson.JSON;
import com.gs.process.core.configuration.ProcessConfig;
import com.gs.process.core.user.ProcessUserService;
import com.gs.process.core.utils.HttpTokenUtil;
import com.gs.process.model.ApprovalDetails;
import com.shallowUniverse.http.HttpApiService;
import com.shallowUniverse.http.pojo.HttpResult;
import com.shallowUniverse.model.Result;
import lombok.Data;

/**
 * @author: Shuai Guo
 * @description:
 * @date: 2021/9/28
 * @version: 1.0
 */
@Data
public class ApprovalDetailsApi {

    private static final String SERVICE = "/approval/details";
    private HttpApiService httpApiService;
    private ProcessConfig processConfig;
    private ProcessUserService processUserService;

    public Result<Long> save(ApprovalDetails approvalDetails) {
        try {
            HttpResult httpResult = httpApiService.doPost(processConfig.getServerUrl() + SERVICE + "/save", HttpTokenUtil.tokenHeaders(), approvalDetails);
            //转换
            return (Result<Long>) JSON.parseObject(httpResult.getBody(), Result.class);
        } catch (Exception e) {
            e.printStackTrace();
            Result<Long> result = new Result<>();
            result.setCode(500).setMessage("调用失败");
            return result;
        }
    }
}
